﻿using GameServer.Networking.Packets;

using GameServer.Managers;

namespace GameServer.Networking.Handlers
{
    class HANDLE_CHANNEL_SWITCH : PacketHandler
    {
        public override void Handle(GameServer.Virtual_Objects.User.virtualUser User)
        {
            try
            {
                int TargetChannel = int.Parse(getNextBlock());

                if (TargetChannel == 1 || User.Rank > 2 || TargetChannel == 4)
                {
                    User.Channel = TargetChannel;
                    User.Page = 0;
                    User.send(new PACKET_CHANGE_CHANNEL(User));
                    User.send(new PACKET_ROOM_LIST(User, User.Page));
                }
                else
                {
                    User.Channel = 1;
                    User.Page = 0;
                    User.send(new PACKET_CHANGE_CHANNEL(User));
                    User.send(new PACKET_ROOM_LIST(User, User.Page));
                    if (TargetChannel != -1)
                    {
                        User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Room_ToAll, "SYSTEM >> This Channel is not avaible yet!", 999, "NULL"));
                    }
                }
            }
            catch { }
        }
    }
}
